package com.nondo.rdp.finance.repository;

import com.nondo.rdp.core.common.StatusConstant;
import com.nondo.rdp.auth.domain.User;
import com.nondo.rdp.finance.domain.UserFollow;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface UserFollowRepository extends JpaRepository<UserFollow, Long>, JpaSpecificationExecutor<UserFollow> {
    @Query("select a from UserFollow a where a.id=:id and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
    Optional<UserFollow> findOne(@Param("id") int id);

    @Modifying
    @Query("update UserFollow set delFlag='" + StatusConstant.DEL_FLAG_DELETE + "' where id = ?1")
    void deleteById(Long id);

    UserFollow save(UserFollow userFollow);

    UserFollow findByFollowerAndUser(User follower, User user);
}
